<?php

$user = $_POST["user"];
$kword = $user ? "bal" : trim($_POST["keyword"]);

$data = array(
	"subject" => array(
		301 => "football",		
		302 => "Personnel changes",
		303 => "winter sports",
		304 => "tennis",
		305 => "voleyball",
		306 => "Economy"
	),
	"people" => array(
		201 => "Rovaniemi",
		202 => "Angelina Jolly",
		203 => "Steve Jobs",
		204 => "Djordje Balasevic",
		205 => "Brad Pitt"
	),
	"geo" => array(
		101 => "Italy",
		102 => "Westminster city hall, GB",
		103 => "Germany",
		104 => "Oulu, FI",
		105 => "Spain",
		106 => "United Kingdom",
		107 => "Asia",
		108 => "Europe",
		109 => "North America",
		110 => "South America"
	)
);

$result = array();
if(strlen($kword)){
	foreach($data as $type=>$d){
		foreach($d as $id=>$name){
			if(stristr($name,$kword)){
				$result[] = array(
					"id" => $id,
					"name" => $name,
					"type" => $type
				);
			}
		}
	}
}

echo json_encode($result);	

?>